package zmee.pmas.form;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.pmgt.pmas.formplugin.pro.ProApprovalAdjustEditPlugin;

import java.math.BigDecimal;
import java.util.EventObject;

/**
 * @Author: zyj
 * @Date: 2023/8/30 13:39
 * @Description: 项目信息调整: 修改标准插件 增加原项目概算总额
 */
public class ProApprovalAdjustEditPluginExt extends ProApprovalAdjustEditPlugin {

    @Override
    public void beforeBindData(EventObject e) {
        super.beforeBindData(e);
        // 项目立项id
        Object projApprovalId = this.getView().getFormShowParameter().getCustomParam("projApprovalId");
        if (projApprovalId != null) {
            // 查询项目立项
            DynamicObject approval = BusinessDataServiceHelper.loadSingle(projApprovalId, "pmas_pro_approval");
            // 获取预算项目
            DynamicObject project = approval.getDynamicObject("pro");
            // 根据项目和有效查询项目支出预算
            QFilter qFilter = new QFilter("project.number", QCP.equals, project.getString("number"));
            QFilter qFilter1 = new QFilter("isvalid", QCP.equals, true);
            DynamicObject[] outbudgets = BusinessDataServiceHelper.load("pmas_outbudget", "id, zmee_textfield", new QFilter[]{qFilter, qFilter1});
            if (outbudgets != null && outbudgets.length != 0) {
                // 获取支出预算的项目概算总额
                BigDecimal projectPlanAmount = outbudgets[0].getBigDecimal("zmee_textfield");
                this.getModel().setValue("zmee_oldprojectplanamt", projectPlanAmount);
            }
        }
    }
}
